package com.it.park.controller.admin;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.it.park.client.service.BookService;
import com.it.park.model.Book;

@Controller
@RequestMapping("/expose/book")
public class AdminBookController {
	
	@Autowired
	private BookService bookService;
	
	/**
	 *显示图片
	 */
	@RequestMapping("showImgShow/{id}")
	public void showPicture(@PathVariable("id")Integer id,HttpServletResponse response) throws IOException{
		Book book =	bookService.selectByPrimaryKey(id);
		byte[] data = book.getBookImg();
		response.setContentType("image/jpg");
		response.setCharacterEncoding("utf-8");
		OutputStream os = response.getOutputStream();
		InputStream is = new ByteArrayInputStream(data);
		int len = 0;
		byte[] b = new byte[1024];
		while((len = is.read(b)) != -1){
			os.write(b, 0, len);
		}
		os.close();
		is.close();
}
	
}
